<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增核酸检查信息</title>
</head>
<script src="/js/jquery-3.7.0.js"></script>
<body>
<form id="fm" th:action="@{/addMedical}" method="post">
    <table border="1">
        <tr>
            <th colspan="2" ><h2>添加核酸信息</h2></th>
        </tr>
        <tr>
            <td>被检查人姓名(*)</td>
            <td><input type="text" id="name" name="assayUser"></td>
        </tr>
        <tr>
            <td>被检查人手机号(*)</td>
            <td><input type="text" id="phone" name="phone"></td>
        </tr>
        <tr>
            <td>被检查人身份证(*)</td>
            <td><input type="text" id="cardNum" name="cardNum"></td>
        </tr>
        <tr>
            <td>检测机构(*)</td>
            <td>   <select name="hospitalId" id="sel">
                <option  value="">————请选择————</option>
            </select></td>
        </tr>
        <tr>
            <td>检测日期(*)</td>
            <td><input type="text" id="assayTime" name="assayTime"></td>
        </tr>
        <tr style="text-align: center">
            <td colspan="2"><input type="submit" value="添加">
                <input type="button" value="返回" onclick="backIndex()">
            </td>
            <script>
              function  backIndex(){
                  location.href='http://localhost:8080/index';
              }
            </script>
        </tr>
    </table>
</form>
</body>
<script>
    $(function (){
        $.ajax({
            url:"http://localhost:8080/hospital",
            type:"get",
            success:function (data){
                $.each(data,function (index,item){
                    $("#sel").append($('<option>',{
                        value:item.id,
                        text:item.name
                    }))
                });
            }
        });
        $("#fm").submit(function (){
            let name=$("#name").val().trim();
            let phone=$("#phone").val().trim();
            let cardNum=$("#cardNum").val().trim();
            let hId=$("#sel").val();
            let assayTime=$("#assayTime").val();
            if (name==null || name=='' ||
                phone==null || phone=='' ||
                cardNum==null || cardNum=='' ||
                hId==null || hId=='' ||
                assayTime==null || assayTime==''){
                alert("请填写完整的核酸检查信息!")
                return false;
            }
            let reg=/^\d{4}-(0[1-9]|1[0-2])-([0-2][1-9]|[1-2][1-9]|3[0-1])$/
            if (reg.test(assayTime)==false){
                alert("日期格式不正确!")
                return  false;
            }
            return  true;
        })
    })
</script>
</html>